$(function(){
	//detail
	$("#wxShow").click(function(){
		$("#wxCode").show();
	});
	$("#wxCode").click(function(){
		$("#wxCode").hide();
	});
	//点赞
	var key =location.pathname;
    console.log(key);
	if(localStorage[key]){
		$("#up").addClass('have');
	};
	$("#up").click(function(){
		if(!$(this).hasClass('have')){
			//发送请求
            str = key.split('-');
            var type = str[0];
            var id = str[1].split('.')[0];
            var page_type = $(this).data("type");
            if( page_type == 'article' ){
                var url = "/nomup-"+id+".html";
            }else{
                var url = "/site-up-"+id+".html";
            }
            $.get(url, function(result){
                if( result.ret ){
                    console.log('成功');
                    var _this = $("#up");
                    _this.addClass('have');
                    localStorage[key]="1";
                    var num = _this.html()*1+1;
                    _this.html(num);
                }
            });

		}
	});
	//home
    var loading = false;
    //上拉加载更多
    $('#home').swipeUp(function(){
    	console.log('222');
        if(!loading){//不是在load
            loading = true;
            getHistory();
            loading = false;
        };
    });
    var getHistory = function(){
        loading = true;
        var lastid = $("#lastid").text();
        var authorid = $("#authorid").text();
        $.get("/homemore.html?authorid="+authorid+"&lastid="+lastid, function(result){
            if( result.ret ){
                $("#lastid").text(result.lastid);
                $("#home").append(result.data);
            }else{
                if( $(".content-end").length <= 0 ){
                    $("#home").after('<p class="content-end"><i></i>我是有底线的<i></i></p>');
                }
            }
        });
    };

    //tag page
    var loading = false;
    //上拉加载更多
    $('#tag').swipeUp(function(){
        console.log('222');
        if(!loading){//不是在load
            loading = true;
            getHistory();
            loading = false;
        };
    });
    var getHistory = function(){
        loading = true;
        var lastid = $("#lastid").text();
        var authorid = $("#tagid").text();
        $.get("/tagmore.html?tagid="+authorid+"&lastid="+lastid, function(result){
            if( result.ret ){
                $("#lastid").text(result.lastid);
                $("#tag").append(result.data);
            }else{
                if( $(".content-end").length <= 0 ){
                    $("#tag").after('<p class="content-end"><i></i>我是有底线的<i></i></p>');
                }
            }
        });
    };

/*
    //tag点赞
    var key = "tagpage";
    if(localStorage[key]){
        $("#up").addClass('have');
    };
    $("#up").click(function(){
        if(!$(this).hasClass('have')){
            //发送请求
            str = key.split('-');
            var type = str[0];
            var id = str[1].split('.')[0];
            $.get("/site-up-"+id+".html", function(result){
                if( result.ret ){
                    console.log('成功');
                    var _this = $("#up");
                    _this.addClass('have');
                    localStorage[key]="1";
                    var num = _this.html()*1+1;
                    _this.html(num);
                }
            });

        }
    });

    */
});
